package com.eagle.security.dao;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.provisioning.GroupManager;
import org.springframework.util.Assert;

import com.eagle.security.entries.RoleGroup;

public interface GroupDao extends GroupManager {
    /**
     * 返回所有角色组的名字列表
     * Returns the names of all groups that this group manager controls.
     */
    List<String> findAllGroups();

    /**
     * 返回某一角色组下的所有用户名 列表
     * Locates the users who are members of a group
     *
     * @param groupName the group whose members are required
     * @return the usernames of the group members
     */
    List<String> findUsersInGroup(String groupName);

    /**
     * 新建一个角色组及其权限
     * Creates a new group with the specified list of authorities.
     *
     * @param groupName the name for the new group
     * @param authorities the authorities which are to be allocated to this group.
     */
    void createGroup(String groupName, List<GrantedAuthority> authorities);

    /**
     * 删除一个角色组以及相关信息，如角色组权限、用户与角色组的对应关系
     * Removes a group, including all members and authorities.
     *
     * @param groupName the group to remove.
     */
    void deleteGroup(String groupName);

    /**
     * 从命名一个角色组
     * Changes the name of a group without altering the assigned authorities or members.
     */
    void renameGroup(String oldName, String newName);

    /**
     * 把一个用户添加到角色组中
     * Makes a user a member of a particular group.
     *
     * @param username the user to be given membership.
     * @param group the name of the group to which the user will be added.
     */
    void addUserToGroup(String username, String group);

    /**
     * 从角色组中，删除一个用户
     * Deletes a user's membership of a group.
     *
     * @param username the user
     * @param groupName the group to remove them from
     */
    void removeUserFromGroup(String username, String groupName);

    /**
     * 获取一个角色组的权限列表
     * Obtains the list of authorities which are assigned to a group.
     */
    List<GrantedAuthority> findGroupAuthorities(String groupName);

    /**
     * 给角色组增加一个权限
     * Assigns a new authority to a group.
     */
    void addGroupAuthority(String groupName, GrantedAuthority authority);

    /**
     * 从角色组中删除一个权限
     * Deletes an authority from those assigned to a group
     */
    void removeGroupAuthority(String groupName, GrantedAuthority authority);
    //----------------------------------------------------------------------------- self ---------------------------------------------------------------------
    
    /**
     * 删除角色组的所有权限
     * @param id
     * @return
     */
    int removeGroupAuthoritysById( String id);
    /**
     * 批量增加角色组的权限
     * @param id
     * @param authoritys
     * @return
     */
    int addGroupAuthoritys( String id, List<GrantedAuthority> authoritys );
    
    /**
     * 获取一个角色组的权限列表
     * @param groupId
     * @return
     */
    List<GrantedAuthority> findGroupAuthoritiesById(String groupId);
    
    /**
     * 把一个用户添加到角色组中
     * @param username	用户名
     * @param groupId	组ID
     */
    void addUserToGroupById(String username, String groupId );
    
    /**
     * 把用户从角色组中删除
     * @param username
     * @param groupName
     */
    void removeUserFromGroupById( String username, String groupId );
    
    /**
     * 删除所有角色组中的 此用户username
     * @param username
     */
    void removeUserFromAllGroup( String username  );
    
    /**
     * find
     * 
     * @param groupname
     * @return
     */
    RoleGroup findRoleGroupByName(String groupname );

    /**
     * find
     * 
     * @param groupname
     * @return
     */
    Map<String, Object> findRoleGroupMapByName(String groupname );

    /**
     * 根据条件查找
     * 
     * @param mo
     * @param start
     * @param pageSize
     * @return
     */
    List<RoleGroup> findRoleGroupsByCond(RoleGroup mo, int start, int pageSize);

    /**
     * 根据条件查找
     * 
     * @param mo
     * @param start
     * @param pageSize
     * @return
     */
    List<Map<String, Object>> findRoleGroupMapsByCond(RoleGroup mo, int start, int pageSize);

    /**
     * 根据条件查找总数
     * 
     * @param mo
     * @return
     */
    int findRoleGroupCountByCond(RoleGroup mo);

    /**
     * 修改角色组
     * @param mo
     * @return
     */
	int modifyRoleGroup( RoleGroup mo );

}
